﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.MovieRecorder.CUiMRCRecorderLabelIndicator
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Interop;
using System.Windows.Markup;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Tecnomatix.Engineering;


namespace DnProcessSimulateCommands.MovieRecorder;

public class CUiMRCRecorderLabelIndicator : Window, ITxViewerFloatingWindow, IComponentConnector
{
  private TxMovieTimeSource _timeSource;
  private double _timeInterval;
  internal Ellipse RedCircle;
  internal TextBlock m_timeSettings;
  private bool _contentLoaded;

  public CUiMRCRecorderLabelIndicator() => this.InitializeComponent();

  private void Window_Loaded(object sender, RoutedEventArgs e)
  {
    HwndSource.FromHwnd(new WindowInteropHelper((Window) this).Handle).AddHook(new HwndSourceHook(this.WndProc));
    TxApplication.Options.Units.TimeUnitsChanged += new TxUnitsOptions_TimeUnitsChangedEventHandler(this.Units_TimeUnitsChanged);
  }

  private void Window_Closed(object sender, EventArgs e)
  {
    (this.FindResource((object) "BlinkDot") as Storyboard).Stop();
    TxApplication.Options.Units.TimeUnitsChanged -= new TxUnitsOptions_TimeUnitsChangedEventHandler(this.Units_TimeUnitsChanged);
  }

  public void PreviewMode(bool on)
  {
    Storyboard resource = this.FindResource((object) "BlinkDot") as Storyboard;
    if (on)
      resource.Begin();
    else
      resource.Stop();
  }

  public void TimeIndication(TxMovieTimeSource timeSource, double timeInterval)
  {
    this._timeSource = timeSource;
    this._timeInterval = timeInterval;
    this.UpdateText();
  }

  private void UpdateText()
  {
    this.m_timeSettings.Visibility = Visibility.Collapsed;
    if (this._timeSource == null)
    {
      this.m_timeSettings.Text = MRCStringTable.MOVIE_RECORDER_SETTINGS_TIMESOURCE_REALTIME;
    }
    else
    {
      string str = MRCStringTable.MOVIE_RECORDER_SETTINGS_TIMESOURCE_SIMTIME;
      if (this._timeInterval > 0.0)
        str = str + Environment.NewLine + string.Format(MRCStringTable.MOVIE_RECORDER_INDICATOR_TIMESOURCE_SIMTIME_INTERVAL, (object) (this._timeInterval / TxApplication.Options.Units.TimeMultiplier).ToString("F" + TxApplication.Options.Units.TimeDigitsAfterDecimalPoint.ToString()));
      this.m_timeSettings.Text = str;
    }
    this.m_timeSettings.Visibility = Visibility.Visible;
  }

  private void Units_TimeUnitsChanged(object sender, TxUnitsOptions_TimeUnitsChangedEventArgs args)
  {
    this.UpdateText();
  }

  public IntPtr Handle => new WindowInteropHelper((Window) this).Handle;

  public int Left => 20;

  public int Top => 20;

  private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
  {
    if (msg != 33)
      return IntPtr.Zero;
    handled = true;
    return new IntPtr(3);
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  public void InitializeComponent()
  {
    if (this._contentLoaded)
      return;
    this._contentLoaded = true;
    Application.LoadComponent((object) this, new Uri("/DnProcessSimulateCommands;component/movierecorder/recordingindication/cuimrcrecorderlabelindicator.xaml", UriKind.Relative));
  }

  [DebuggerNonUserCode]
  [GeneratedCode("PresentationBuildTasks", "4.0.0.0")]
  [EditorBrowsable(EditorBrowsableState.Never)]
  void IComponentConnector.Connect(int connectionId, object target)
  {
    switch (connectionId)
    {
      case 1:
        ((FrameworkElement) target).Loaded += new RoutedEventHandler(this.Window_Loaded);
        ((Window) target).Closed += new EventHandler(this.Window_Closed);
        break;
      case 2:
        this.RedCircle = (Ellipse) target;
        break;
      case 3:
        this.m_timeSettings = (TextBlock) target;
        break;
      default:
        this._contentLoaded = true;
        break;
    }
  }
}
